<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html lang="zh-ch">
<head>
<meta charset="utf-8">
<title>简洛订餐系统-店铺管理</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<jsp:include page="/WEB-INF/views/inc/inc.jsp"></jsp:include>

</head>
<body style="zoom: 1;">
<jsp:include page="/WEB-INF/views/inc/Header.jsp"></jsp:include>
<jsp:include page="/WEB-INF/views/inc/Inc01.jsp"></jsp:include>
<div class="container" style="margin-top:5px;">
  
  <div class="row border">
    <div class="col-xs-12 btn-group-xs"  style="padding-left:10px; padding-top:5px; padding-bottom:5px; border-bottom:solid 1px #ccc;">
      <button type="button" class="button bg-main button-small dialogs" data-toggle="click" data-target="#addShopModal" data-mask="1" data-width="20%">
      <span class="icon-plus text-white"></span> 添加</button>
      <button type="button" class="button bg-main button-small" id="deleteBut" data-toggle="click" data-target="#delConfirmationModal" data-mask="1" data-width="20%">
      <span class="icon-trash-o text-white"></span> 删除</button>
    </div> 
    <div class="col-xs-12 " style="margin:0px;">
    <form action="DeleteShop.nut" method="post" id="tableForm">
        <table class="table table-striped">
            <thead>
              <tr>
                <th width="5%"></th>
                <th width="25%">名称</th>
                <th width="50%">地址</th>
                <th width="20%">操作</th>
              </tr>
            </thead>
            <tbody>
            <c:forEach var="shop" items="${obj}">
              <tr>
                <td>
                 <label class="checkbox" for="checkbox1" style="margin:5px;">
                   <input type="checkbox" value="${shop.sid }" id="checkbox1" name="sids" data-toggle="checkbox">
                </label>
                </td>
                <td >${shop.sname }</td>
                <td >${shop.saddress }</td>
                <td >
                    <button type="button" buttype="update" class="button bg-sub  button-little radius-rounded" 
                    data-toggle="click" data-mask="1" data-z-index="100" data-width="30%" data-target="#updateShopModal" 
                    sid="${shop.sid}">
                    <span class="icon-edit text-white"></span> 修改</button>
                    <a  class="button bg-sub  button-little radius-rounded" href="MenuManager.nut?sid=${shop.sid }">
                    <span class="icon-list-alt text-white"></span> 管理菜单</a>
                </td>
              </tr>
            </c:forEach>
            </tbody>
          </table>
     </form>     
    </div>
  </div>
</div>

<!-- Add Shop Modal -->
<div id="addShopModal" >
  <div class="dialog fadein-top">
     <div class="dialog-head">
       <span class="close rotate-hover "></span>
       <strong>添加店铺</strong>
     </div>
     <form id="addShopForm" action="AddShop.nut" method="post">
     <div class="dialog-body" > 
       <div class="login-form">
         <div class="input-group " style="margin:10px 0px;">
           <span class="input-group-addon">名　称：</span>
           <input type="text" class="form-control login-field" id="login-name" name="sname"/>
         </div>

         <div class="input-group" style="margin:10px 0px; ">
           <span class="input-group-addon">地　址：</span>
           <input type="text" class="form-control login-field" id="login-pass" name="saddress"/>
         </div>
         </div>
       </div>
     </form>
     <div class="dialog-foot">
         <button type="button" class="button dialog-close" data-dismiss="modal">关闭</button>
         <button type="button" id="addShopBut" class="button bg-green" >提交</button>
     </div>
  </div>
</div>
<!-- / Add Shop Modal -->

<!-- Update Shop Modal -->
<div id="updateShopModal">
  <div class="dialog fadein-top">
     <div class="dialog-head">
       <span class="close rotate-hover "></span>
       <strong>修改店铺</strong>
     </div>
     <form id="updateShopForm" action="UpdateShop.nut" method="post">
     <div class="dialog-body" > 
       <div class="login-form">
         <div class="input-group " style="margin:10px 0px;">
           <span class="input-group-addon">名　称：</span>
           <input type="text" class="form-control login-field" id="login-name" name="sname"/>
           <input type="hidden" id="sid" name="sid"/>
         </div>

         <div class="input-group" style="margin:10px 0px; ">
           <span class="input-group-addon">地　址：</span>
           <input type="text" class="form-control login-field" id="login-pass" name="saddress"/>
         </div>
         </div>
       </div>
     </form>
     <div class="dialog-foot">
         <button type="button" class="button dialog-close" data-dismiss="modal">关闭</button>
         <button type="button" id="updateShopBut" class="button bg-green">提交</button>
     </div>
  </div>
</div>
<!-- / Update Shop Modal -->

<!-- Delete Shop Confirmation Modal -->
<div id="delConfirmationModal">
    <div class="dialog fadein-top">
       <div class="dialog-head">
           <span class="close rotate-hover "></span>
           <strong>确认删除</strong>
       </div>
       <div class="dialog-body">
       请确认是否删除已选店铺？
       </div>
       <div class="dialog-foot">
           <button type="button" class="button dialog-close" data-dismiss="modal">取消</button>
           <button type="button" class="button bg-green" id="confDelUserBut">确定</button>
       </div>
    </div>
</div>
<!-- / Delete Shop Confirmation Modal -->
<script type="text/javascript">
$(function(){
	
	function message(mess){
		var alertMess ="<div name=\"alertMessage\" class=\"alert alert-warning alert-dismissible\" role=\"alert\">";
        alertMess += "<button type=\"button\" class=\"close\" data-dismiss=\"alert\"><span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span></button>";
        alertMess += "<strong>警告!</strong>" + mess;
        alertMess += "</div>";
        return alertMess;
	}
	
	function checkForm(obj, sname){
		if (sname == "") {
            var alertMess = message("店铺名称不能为空.");
            $('div[name="alertMessage"]').remove()
            $(alertMess).insertBefore(obj);
            return false;
        }
	    return true;
	}
	
	$("#addShopBut").click(function(){
		var e = $(this);
		var sname = $("#addShopModal input[name='sname']").val();
		var saddress = $("#addShopModal input[name='saddress']").val();
		if (!checkForm("#addShopBut", sname)) {
            return;
        }
		$('div[name="alertMessage"]').remove()
		$("#addShopForm").submit();
// 		$showdialogs(e);
	});
	
	$("#updateShopBut").click(function(){
		var sname = $("#updateShopModal input[name='sname']").val();
		var saddress = $("#updateShopModal input[name='saddress']").val();
		if (!checkForm("#updateShopBut", sname)) {
            return;
        }
		$('div[name="alertMessage"]').remove()
		$("#updateShopForm").submit();
	});
	
	// 点击更新按钮
    $("button[buttype='update']").click(function(){
        var sid = $(this).attr("sid");
        var e = $(this);
        $.getJSON("InitShopUpdate.nut", {"sid":sid}, function(data){
            $("#updateShopModal input[name='sid']").val(data.message.sid);
            $("#updateShopModal input[name='sname']").val(data.message.sname);
            $("#updateShopModal input[name='sname']").attr("readonly", "readonly");
            $("#updateShopModal input[name='saddress']").val(data.message.saddress);
//             $("#updateShopModal").modal();
            $showdialogs(e);
        });
    });
	
    // 删除按钮
    $("#deleteBut").click(function(){
    	var e = $(this);
        var str="";
        var sids = $("input[name='sids']:checked");
        if(sids.length > 0){
//             $("#delConfirmationModal").modal();
            $showdialogs(e);
        }
    });
    
    // 确认删除按钮
    $("#confDelUserBut").click(function(){
        $('#tableForm').submit();
    });
});

</script>


</body>
</html>